<script>
import axios from "axios";
import {getBaseUrl} from "@/js/common.js";

export default {
  name: "BlogInfoDialog",
  data() {
    return {
      dialogVisible: false,
      formData: {}
    }
  },
  props: {
    blog: {
      type: Object,
      default: () => {}
    }
  },
  methods: {
    open() {
      this.formData = {
        id: this.blog.id,
        title: this.blog.title,
        cover: this.blog.cover
      }
    },
    edit() {
      axios.post(getBaseUrl('blogHandle') + '/blog/update', this.formData, {headers: {massToken: sessionStorage.getItem('massToken')}}).then(res => {
        if (res.data.code === 200) {
          this.$message({
            type: 'success',
            message: '修改成功!'
          });
          this.dialogVisible = false
          this.$emit('getDataList')
          return
        }
        this.$emit('getDataList')
      })
    }
  }
}
</script>

<template>
  <div>
    <el-dialog v-model="dialogVisible" width="30%" @open="open">
      <el-form>
        <el-form-item label="标题">
          <el-input v-model="formData.title"></el-input>
        </el-form-item>
        <el-form-item label="封面">
          <el-input v-model="formData.cover"></el-input>
        </el-form-item>
        <el-form-item>
          <div style="text-align: center;width: 100%">
            <el-button type="primary" size="small" @click="edit">修改</el-button>
            <el-button size="small" @click="dialogVisible=false">取消</el-button>
          </div>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<style scoped>

</style>
